﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; 
using MySql.Data.MySqlClient;

namespace MySQLLib
{
    public class Guild_members
    {
        string[,] _guild_members;
        private MySqlConnection conn;

        public void setConnection(MySqlConnection connection)
        {
            this.conn = connection;
        }

        public void refresh()
        {
            string[] column = new string[1];
            column[0] = "*";

            this._guild_members = Query.SelectQuery(this.conn, "guild_members", column);
        }

        public string[,] Members
        {
            get { return this._guild_members; }
        }

        public string[,] getMembersFromGuild(int id, bool refresh = false)
        {
            if (refresh)
                this.refresh();

            string[,] members = new string[0, this._guild_members.GetLength(1)];

            for (int i = 0; i < this._guild_members.GetLength(0); i++)
            {
                if (this._guild_members[i, 1] == id.ToString())
                {
                    Other.ResizetwoDimensArray(ref members, this._guild_members.GetLength(1), this._guild_members.GetLength(0) + 1);
                    for (int i2 = 0; i2 < this._guild_members.GetLength(1); i2++)
                    {
                        members[members.GetLength(0) - 1, i2] = this._guild_members[i, i2];
                    }
                }
            }

            return members;
        }

        public void addMember(int guildid, int guildmemberid, int rank, int points, int auth, string grand, int p, int perm)
        {
            string[] columns = { "guild_id", "guild_member_id", "guild_rank", "guild_points", "guild_auth", "guild_grant", "guild_p", "guild_perm" };
            string[] values = { guildid.ToString(), guildmemberid.ToString(), rank.ToString(), points.ToString(), auth.ToString(), grand, p.ToString(), perm.ToString() };
            Query.InsertQuery(this.conn, "guild_members", columns, values);
        }
    }
}
